<?php

namespace App\Service\Auth\v1_3_4;

use App\Constants\ErrorCode;
use App\Model\SocialAccount;
use App\Model\User;
use App\Service\Auth\AuthBaseService;

/**
 * 解绑QQ或者微信账号
 */
class UnbindSocialService extends AuthBaseService
{
    protected $socialProvider = [
        1 => 'qq',
        2 => 'weixin',
    ];

    protected function RoVerifyList()
    {
        return [
            'provider' => "required|string",
        ];
    }

    public function handle()
    {
        $provider = $this->request->input('provider');
        $userId = $this->getUserId();
        if (!in_array($provider, $this->socialProvider)) {
            return $this->setError(ErrorCode::PARAMETER_ERROR, '暂无该第三方平台操作！');
        }
        //是否存在第三方注册账号
        $socialAccount = SocialAccount::checkUser($provider, $userId);
        if (!$socialAccount) {
            return $this->setError(ErrorCode::SOCIAL_UNBIND, '账号还未绑定该第三方平台！');
        }
        //返回数组
        $result = SocialAccount::unbind($provider, $userId);
        $ret = ['result' => $result];
        return $ret;
    }
}
